//
//  HJDefaultCenterView.m
//  newOcWeibo
//
//  Created by heJing on 15/7/27.
//  Copyright © 2015年 heima. All rights reserved.
//

#import "HJDefaultCenterView.h"

@interface HJDefaultCenterView()

/**转盘*/
@property (weak, nonatomic) IBOutlet UIImageView *turnView;

/**中间icon*/
@property (weak, nonatomic) IBOutlet UIImageView *icon;

/**显示文本*/
@property (weak, nonatomic) IBOutlet UILabel *info;

@property (weak, nonatomic) IBOutlet UIButton *registerBtn;

@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

-(IBAction)loginBtnClick:(id)sender;

-(IBAction)registerBtnClick:(UIButton *)rgsBtn;

@property(nonatomic, strong)CADisplayLink *link;


@end

@implementation HJDefaultCenterView

// 快速创建类
+ (instancetype)defaultCenterView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"HJDefaultCenterView" owner:nil options:nil] lastObject];
}


-(IBAction)loginBtnClick:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(defaultCenterView:loginButton:)]){
        
        [self.delegate defaultCenterView:self loginButton:sender];
    }
    NSLog(@"登陆按钮被点击");
}

-(IBAction)registerBtnClick:(UIButton *)rgsBtn
{
    if ([self.delegate respondsToSelector:@selector(defaultCenterView:registerButton:)]) {
        
        [self.delegate defaultCenterView:self registerButton:rgsBtn];
    }
    NSLog(@"注册按钮被点击");
}

// 通过外部设置内部的控件文字
-(void)setInfoStr:(NSString *)infoStr
{
    //    _infoStr = infoStr;
    self.info.text = infoStr;
}

// 设置图片名字
- (void)setIconImageName:(NSString *)iconImageName
{
    //    _iconImageName = iconImageName;
    self.icon.image = [UIImage imageNamed:iconImageName];
}

-(void)setShow:(BOOL)show
{
    _show = show;
    if (_show) {
        
        self.turnView.hidden = NO;
        
    }
}


-(void)startRotate
{
    self.link.paused = NO;
}

-(void)stopRotate
{
    self.link.paused = YES;
}

#pragma mark - lazy
- (CADisplayLink *)link
{
    if (!_link) {
        _link = [CADisplayLink  displayLinkWithTarget:self selector:@selector(update)];
        [_link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
    }
    return _link;
}
- (void)update{
    
    //    HJLog(@"%s",__func__);
    // 开始旋转
    self.turnView.transform = CGAffineTransformRotate(self.turnView.transform, M_PI / 100);
}



@end
